var http = require('http')
var fs = require('fs')
var io = require('socket.io')
var server = http.createServer((req, res) => {
  fs.readFile('./postMessage.html', (err, data) => {
    res.writeHead(200, {'Content-Type': 'text/html'})
    res.end(data)
  })
}).listen(3000)


io.listen(server).sockets.on('connection', (socket) => {
  socket.on('message', data => {
    socket.broadcast.emit('push message', data)
    console.log(data)
  })
})